using System;
using System.Windows.Media;
using Prism.Mvvm;

namespace Prism.AvalonDock.Extensions.ViewModels
{
    public abstract class DockWindowViewModel : BindableBase, IDisposable
    {
        #region Properties
        #region CanClose
        private bool _canClose;
        public bool CanClose
        {
            get
            {
                return _canClose;
            }
            set
            {
                if (_canClose != value)
                {
                    _canClose = value;
                    RaisePropertyChanged(nameof(CanClose));
                }
            }
        }
        #endregion

        #region CanFloat
        private bool _canFloat;
        public bool CanFloat
        {
            get
            {
                return _canFloat;
            }
            set
            {
                if (_canFloat != value)
                {
                    _canFloat = value;
                    RaisePropertyChanged(nameof(CanFloat));
                }
            }
        }
        #endregion

        #region Title
        private string _title;
        public string Title
        {
            get
            {
                return _title;
            }
            set
            {
                if (_title != value)
                {
                    _title = value;
                    RaisePropertyChanged(nameof(Title));
                }
            }
        }
        #endregion

        #region IconSource

        private ImageSource _iconSource = null;
        public ImageSource IconSource
        {
            get
            {
                return _iconSource;
            }
            set
            {
                if (_iconSource != value)
                {
                    _iconSource = value;
                    RaisePropertyChanged(nameof(IconSource));
                }
            }
        }

        #endregion

        #endregion

        public DockWindowViewModel()
        {
            CanClose = true;
            CanFloat = true;
        }

        private bool _isInitialized;
        public bool IsInitialized
        {
            get { return _isInitialized; }
            protected set
            {
                if (_isInitialized != value)
                {
                    _isInitialized = value;
                    RaisePropertyChanged(nameof(IsInitialized));
                }
            }
        }

        public virtual void Initialize()
        {
            IsInitialized = true;
        }

        /// <summary>
        /// 释放标记
        /// </summary>
        private bool _disposed;

        ~DockWindowViewModel()
        {
            Dispose(false);
        }

        public virtual void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (_disposed) return;

            if (disposing) //清理托管资源
            {
                //执行基本的清理代码
            }

            //清理非托管资源

            //告诉自己已经被释放
            _disposed = true;
        }
    }
}
